from rest_framework import serializers
from question.models import *
from user.models import User


class LabelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Label
        fields = ['id', 'label_name']


class QuestionsSerializer(serializers.ModelSerializer):
    labels = serializers.StringRelatedField(many=True)
    user = serializers.StringRelatedField()

    class Meta:
        model = Question
        fields = [
            'id',
            'createtime',
            'labels',
            'reply',
            'replyname',
            'replytime',
            'title',
            'unuseful_count',
            'useful_count',
            'use',
            'visits',
        ]


class LabelDSerializer(serializers.ModelSerializer):
    questions = QuestionsSerializer(many=True)
    users = serializers.PrimaryKeyRelatedField(many=True, read_only=True)

    class Meta:
        model = Label
        fields = [
            'id',
            'questions',
            'label_name',
            'desc',
            'baike_url',
            'label_icon',
            'users'
        ]


